<?php
	App::uses('Component', 'Controller');
	class SubCourseComponent extends Component {
		
		public function regist($subId, $courseId){
			$this->SubCourse = ClassRegistry::init('SubCourse');
			$this->SubCourse->create();
			$dataNeedToSave = array('SubCourse' => array('f_sub_id' => $subId,
				                'f_course_id' => $courseId));
			if($this->SubCourse->save($dataNeedToSave)){
		    	return $this->SubCourse->id;
			}
			return 0;
		}
		
		public function getListByCourseId($courseId){
			$this->SubCourse = ClassRegistry::init('SubCourse');
			$subjectList = $this->SubCourse->find('all', array(
				'conditions' => array('SubCourse.f_course_id' => $courseId)
			));
			return $subjectList;
		}
		
		public function deleteByCourse($courseId){
			$this->SubCourse = ClassRegistry::init('SubCourse');
			return $this->SubCourse->deleteAll(array(
				'SubCourse.f_sub_id' => $courseId
			), false);
		}
		
	}
?>